<template>
	<view class="pageview">
		<cl-navbar :title="$t('my_file.privacySecurity.index.title')" leftIconSize="40rpx" placeholder autoBack>
		</cl-navbar>
		<view class="pageContent">
			<view class="cellviewGrop">
				<view class="cellview">
					<view class="cellview__left">
						<text class="cellview__left__title">{{$t('my_file.privacySecurity.index.FriendVerification')}}</text>
					</view>
					<view class="cellview__right">
						<u-switch v-model="user_info.verify_friends" asyncChange  @change="e=>setChange('verify_friends',e)" size="20"
							activeValue="1" inactiveValue="0"></u-switch>
					</view>
				</view>
			</view>
			<view class="cellviewGrop">
				<view class="cellview" @click="goPage('changePassword')">
					<view class="cellview__left">
						<text class="cellview__left__title">{{user_info.is_set_password == '0'?$t('my_file.privacySecurity.index.setPassword'):$t('my_file.privacySecurity.index.changePassword')}}</text>
					</view>
					<view class="cellview__right">
						<u-icon name="arrow-right" color="#B2B2B2"></u-icon>
					</view>
				</view>
			</view>
			<view class="cellviewGrop">
				<view class="cellview" @click="goPage('friend_black')">
					<view class="cellview__left">
						<text class="cellview__left__title">{{$t('addressbook.friend_black.title')}}</text>
					</view>
					<view class="cellview__right">
						<u-icon name="arrow-right" color="#B2B2B2"></u-icon>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import userApi from "@/services/api/user.js"
	import {
		mapState
	} from 'vuex'
	export default {
		name: 'privacy_security',
		data() {
			return {
				passwordData:{
					old_pwd:'',
					new_pwd:'',
					re_new_pwd:''
				}
			}
		},
		computed: {
			...mapState({
				user_info: state => state.user.user_info,
			})
		},
		onLoad() {
			console.log(this.user_info);
		},
		methods: {
			goPage(urlname){
				this.$Router.push({
					name:urlname
				})
			},
			
			async setChange(type, val) {
				let { verify_friends,is_auth } = this.user_info
				
				let data = { verify_friends,is_auth }
				switch (type) {
					case 'verify_friends':
						data.verify_friends = val
						break;
					case 'is_auth':
						data.is_auth = val
						break;
					default:
						break;
				}
				userApi.userEditOther(data)
			},
			//确认修改密码
			async completePopPassword(){
				try{
					let apires = await uni.$api.user.changePassword(this.passwordData)
					console.log(apires);
					if(apires){
						this.passwordData = {
							old_pwd:'',
							new_pwd:'',
							re_new_pwd:''
						}
						this.$refs.clEditPassword.cancel()
					}
				}catch(e){
					//TODO handle the exception
				}
			}
		},
	};
</script>

<style scoped lang="scss">
	.cellviewGrop {
		background: #ffffff;
		border-radius: 20rpx;
		margin: 20rpx 30rpx 0;
	
		.cellview {
			display: flex;
			justify-content: space-between;
			padding: 0 30rpx;
			height: 110rpx;
	
			&__left {
				display: flex;
				align-items: center;
	
	
				&__title {
					font-size: 28rpx;
				}
			}
			&__right{
				display: flex;
				align-items: center;
				&__content{
					font-size: 28rpx;
					color: #61626e;
				}
			}
		}
	}
</style>